package com.multitrack.util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.multitrack.datatype.IdentityList;
import com.multitrack.main.R;

public class EventListAdapter extends BaseAdapter {
	private Context context;
	private IdentityList events;
	private LayoutInflater inflater;
	private int layout;

	public EventListAdapter(Context context, int layout, IdentityList events) {
		this.context = context;
		this.events = events;
		inflater = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.layout = layout;
	}

	public int getCount() {
		return events.size();
	}

	public Object getItem(int pos) {
		return events.get(pos).getName();
	}

	public long getItemId(int pos) {
		return pos;
	}

	public View getView(int pos, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(layout, parent, false);
		}
		
		TextView eventText = (TextView) convertView.findViewById(R.id.event_name);
		eventText.setText(events.get(pos).getName());
		eventText.setSelected(true);

		return convertView;
	}
}